package com.example.kotlinstudy.net

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.google.gson.Gson
import okhttp3.Callback
import okhttp3.MediaType
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.Response
import retrofit2.Retrofit

class TestActiivty : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val info = Info("test", "123456")
        val obj = Gson().toJson(info);

        val retrofit = Retrofit.Builder()
            .baseUrl("")
            .build()

        val requestBody =
            RequestBody.create(MediaType.parse("application/json; charset=utf-8"), obj)
        retrofit.create(APIStore::class.java).getMessage(requestBody)
            ?.enqueue(object : retrofit2.Callback<ResponseBody?> {
                override fun onResponse(
                    call: Call<ResponseBody?>,
                    response: Response<ResponseBody?>
                ) {
                    Log.e("response", "${response.body()?.string()}")

                }

                override fun onFailure(call: Call<ResponseBody?>, t: Throwable) {
                }
            })

    }
}

data class Info(val account: String, val password: String)